package com.wc.alorithm_blue_bridge._动态规划.背包问题.Q2945;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/15 17:25
 * @description
 */

public class Main {
    static int maxN = (int) 1e5 + 7;
    static long[] dp = new long[maxN];
    static FastReader sc = new FastReader();
    static long[][] wvs = new long[maxN][4];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= 3; j++) {
                wvs[i][j] = sc.nextInt();
            }
        }
        Arrays.sort(wvs, 1, n + 1, (o1, o2) -> {
            if (o1[2] == o2[2]) {
                return (int) (o1[3] - o2[3]);
            }
            return (int) (o1[2] - o2[2]);
        });
        for (int i = 1; i <= n; i++) {
            for (int j = (int) wvs[i][2]; j >= (int) wvs[i][1]; j--) {
                dp[j] = Math.max(dp[j], dp[j - (int) wvs[i][1]] + wvs[i][3]);
            }
        }
        long ans = 0;
        for (int i = 1; i < maxN; i++) {
            ans = Math.max(ans, dp[i]);
        }
        System.out.println(ans);
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }
}